<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
		.item{
			width: 80px;
			display: inline-block;
			margin-left: 5px;
		}
	</style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	    	<tr>
	    		<td style="white-space:nowrap;">
	            	<span class="item">名称：</span>
	                <input id="title" class="mini-textbox" emptyText="请输入标题名称" style="width:100px;" />   
	                <span class="item">编号：</span>
	                <input id="serialNum" class="mini-textbox" emptyText="请输入编号" style="width:100px;" />   
	                <span class="item">仓库名称：</span>
	                <input id="warehouseName" class="mini-textbox" emptyText="请输入仓库名称" style="width:100px;" />   
	            </td>
	            <td style="white-space:nowrap;"><a class="mini-button" iconCls="icon-search" onclick="search()">查询</a></td>
	    	</tr>
	        <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/storage_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	                </sec:authorize>
	                <sec:authorize url='/storage_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
	                </sec:authorize>
	                <sec:authorize url='/storage_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">批量删除</a>
	                </sec:authorize>
	                <sec:authorize url='/storage_export.do'>
	         		<a class="mini-button" iconCls="icon-download" onclick="exportData()">导出指定入库单</a>
	         		</sec:authorize>
	            </td>
	            <td style="white-space:nowrap;">
                	&nbsp;
                </td>
	            
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" url="storage_view.do" style="width:100%;height:100%;" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn"></div>
			<div name="action" width="60" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
			<div field="serialNum" width="100" headerAlign="center" align="center">编号</div>
			<div field="title" width="100" headerAlign="center" align="center">标题</div>
			<div field="warehouseName" width="100" headerAlign="center" align="center">仓库</div>
			<div field="storageTime" width="80" allowSort="true" headerAlign="center" align="center">入库时间</div>
			<div field="typeVal" width="100" headerAlign="center" align="center">入库类型</div>
			<div field="status" width="70" headerAlign="center" align="center">状态</div>
			<div field="writeUserName" width="70" headerAlign="center" align="center">填单人</div>
			<div field="auditUserName" width="70" headerAlign="center" align="center">审核人</div>
		</div>
	</div>
	</div>

<script type="text/javascript">
	mini.parse();
	
	var grid = mini.get("datagrid1");
	grid.load();
	
    function search() {
	 	var serialNum = mini.get("serialNum").getValue();
	    var title = mini.get("title").getValue();
	    var warehouseName = mini.get("warehouseName").getValue();
	    grid.load({ serialNum: serialNum,
	    	title: title,
	    	warehouseName: warehouseName,
	    });
	}

	//相关操作
 	function onActionRenderer(e) {
	    var s = '';
		if('3' == e.row.statusVal){
			s = '<sec:authorize url="/storage_detail_init.do"><a style="width:150px;" href="javascript:editDetail()">编辑明细</a></sec:authorize>';
		}else{
			s = '<sec:authorize url="/storage_data_view.do"><a style="width:150px;" href="javascript:viewDetail()">查看详细</a></sec:authorize>';
		}
	    return s;
    }
	
	function add() {
	    mini.open({
	        url: "storage_add.do",
	        allowResize:false,
	        title: "新增入库单", width: 500, height: 350,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action: "new"};
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
	}
	
	function edit() {
        var row = grid.getSelecteds();
        if (row.length == 1) {
        	if(row[0].statusVal == '3'){
        		mini.open({
                    url: "storage_edit.do",
                    allowResize:false,
                    title: "修改入库单信息", width: 500, height: 350,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", row: row[0] };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                    	if(action == 'succ'){
        	        		mini.showMessageBox({
        	                    title: "提示",
        	                    showModal:false,
        	                    iconCls: "mini-messagebox-info",
        	                    message: "修改成功！",
        	                    timeout: 3000,
        	                    x: 'right',
        	                    y: 'bottom'
        	                });
        		            grid.reload();
        	        	}
                    }
                });
        	} else if(row[0].statusVal == '2') {
        		mini.alert("审核未通过，无法修改！");
        	} else {
        		mini.alert("已完成入库，无法修改！");
        	};
        } else {
            mini.alert("请选中一条记录");
        }
    }
	
    function remove() {
    	var rows = grid.getSelecteds();
    	var flag = true;
    	for(var i = 0;i<rows.length;i++){
    		if(rows[i].statusVal != '3') {
    			flag = false;
    			break;
    		}
    	}
    	if (rows.length > 0) {
    		if(flag) {
    			mini.confirm("确定删除选中记录？", "删除",function (action) {
    				if (action == "ok") {
    					var arr = new Array();
	               		$.each(rows,function(i,v){
	               			arr.push(v.id);
	               		});
	               		var rids = arr.join("-");
	               		$.post("storage_del.do",{id:rids},function(text){
	               			if(text.success){
	               				mini.showMessageBox({
		    	                    title: "提示",
		    	                    showModal:false,
		    	                    iconCls: "mini-messagebox-info",
		    	                    message: "删除成功！",
		    	                    timeout: 3000,
		    	                    x: 'right',
		    	                    y: 'bottom'
		    	                });
	               				grid.reload();
	               			}
	               		},"json");
    				}
    			});
	       	}else {
	       		mini.alert("所选记录中包含审核未通过或审核完成入库单，请重新选择！");
	       	};
        } else {
            mini.alert("请选中一条记录");
        }
    }
    
    function editDetail() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "storage_detail_init.do",
                allowResize:false,
                title: "编辑入库明细", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "editDetail", row: row };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                	if(action == 'succ'){
    	        		mini.showMessageBox({
    	                    title: "提示",
    	                    showModal:false,
    	                    iconCls: "mini-messagebox-info",
    	                    message: "提交审核成功！",
    	                    timeout: 3000,
    	                    x: 'right',
    	                    y: 'bottom'
    	                });
    	        		grid.reload();
    	        	}else if(action == 'storage'){
    	        		mini.showMessageBox({
    	                    title: "提示",
    	                    showModal:false,
    	                    iconCls: "mini-messagebox-info",
    	                    message: "批准入库！",
    	                    timeout: 3000,
    	                    x: 'right',
    	                    y: 'bottom'
    	                });
    	        		grid.reload();
    	        	}
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }
    
    function viewDetail() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "storage_data_view.do",
                allowResize:false,
                title: "入库详细数据", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "viewDetail", row: row };
                    iframe.contentWindow.SetData(data);
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }
    
    function exportData() {
        var row = grid.getSelecteds();
        if (row.length == 1) {
           	if (confirm("确定导出选中记录？")) {
         		location.href="storage_export.do?id=" +row[0].id;
           	};	 
        } else {
            mini.alert("请选中一条记录");
        }
    }
    
</script>
</body>
</html>